import Vue from 'vue'
import Router from 'vue-router'
import errorPage from '@/components/errorpage';
import {LoginRoutes} from '@/components/login/router/login.routes.js';
import {IndexRoutes} from '@/components/index/router/index.routes.js';
import {BusinessTripRoutes} from '@/components/businessTrip/router/businessTrip.routes.js';
import {WorkOvertimeRoutes} from '@/components/workOvertime/router/workOvertime.routes.js';
import {ReimbursementRoutes} from '@/components/reimbursement/router/reimbursement.routes.js';
import {DealtRoutes} from '@/components/dealt/router/dealt.routes.js';
import {NoticeRoutes} from '@/components/notice/router/notice.routes.js';
import {Leave} from '@/components/leave/router/leave.routes.js';
import {Egress} from '@/components/egress/router/egress.routes.js';
Vue.use(Router)

let router = new Router({
  // mode: 'history',
  routes: [
    //路径重定向
    { path: '/', redirect: '/login' },
    ...LoginRoutes,
    ...IndexRoutes,
    ...BusinessTripRoutes,
    ...WorkOvertimeRoutes,
    ...ReimbursementRoutes,
    ...DealtRoutes,
    ...NoticeRoutes,
    ...Leave,
    ...Egress,
    //默认错误地址跳转页
    {
      path: '*',
      name: 'errorPage',
      component: errorPage
    }
  ]
});
export default router;

router.beforeEach((to, from, next) => {
  let userinfo = localStorage.UserInfo,
      exceptionList = ['/login','/forget','/reset'];
  // console.log(to.path)
  if (!userinfo && exceptionList.indexOf(to.path) < 0) {
    next({
      path: '/login'
    })
  } else {
    next()
  };
})